//
//  ViewController.swift
//  newproject
//
//  Created by Pro on 2018/1/17.
//  Copyright © 2018年 Pro. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    var textField:UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.cyan
    }
    
    
    override func viewDidAppear(_ animated: Bool){
        super.viewDidAppear(animated)
        
        let button:UIButton = UIButton(type: .system)
        button.frame = CGRect(x:50, y:220, width:150, height:30)
        button.setTitle("2.点击按钮出现弹窗", for:.normal)
        button.backgroundColor = UIColor.white
        button.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
        self.view.addSubview(button)
        
        
        textField = UITextField.init()
        textField.placeholder = "1.在这里输入0或者1来选择模式"
        textField.frame =   CGRect(x: 50, y: 150, width: 270, height: 30)
        textField.backgroundColor = UIColor.white
        view.addSubview(textField)
        
        
    }
    
    @objc func buttonClick(){
        
        let myAlert = UsefulAlertView(frame: CGRect(x: 0 , y: 0, width: UIScreen.main.bounds.width , height: UIScreen.main.bounds.height))
        
        if textField.text == "0"{
            myAlert.statusForDisPlayOut = 0
        }else
        {
            myAlert.statusForDisPlayOut = 1
        }
        
        
        myAlert.cancelButtonCallBack = {() -> () in
            print("just click cancel btn")
        }
        
        myAlert.confirmButtonCallBack = {() -> () in
            print("just click confirm btn")
            
        }
        myAlert.tapGestureCallBack = {() -> () in
            
            print("just click bg view  tap")
            myAlert.removeFromSuperview()
            
        }
        
        self.view.addSubview(myAlert)
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

